package com.base.vistter.iframe.utils;

import java.util.Random;
import java.util.UUID;

public class StringUtils {

    public static final String NUMBER_CHARACTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    /**
     * uuid
     * @return
     */
    public static String uuid(){
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 6位随机数
     * @return
     */
    public static String randomNum(){
        Random r = new Random();
        int result = r.nextInt(1000000);
        return result < 100000 ? String.valueOf(result + 100000) :  String.valueOf(result);
    }

    public static String generateRandomString(int length) {
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(NUMBER_CHARACTER.length());
            char randomChar = NUMBER_CHARACTER.charAt(index);
            sb.append(randomChar);
        }
        return sb.toString();
    }

}
